package brightgrove.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

/**
 * Created by alaktionov on 22.10.2014.
 */
public class MovieDetailPage extends InternalPage {
    public MovieDetailPage(PageManager pages) {
        super(pages);
    }

    @FindBy (css = "#content > section > nav > ul > li:nth-child(3) > div > div > a > img")
    private WebElement editButton;

    @FindBy (xpath = "//*[@id=\"content\"]/section/nav/ul/li[4]/div/div/a/img")
    private WebElement removeButton;

    @FindBy (css = "#movie > div.maininfo_full > h2")
    private WebElement nameOfFilm;

    public WebElement getRemoveButton() {
        return removeButton;
    }

    public WebElement getEditButton() {
        return editButton;
    }

    public String getNameOfCreatedFilm() {
        return nameOfFilm.getAttribute("value");
    }

    public void clickEditButton() {
        editButton.click();
    }

    public void clickRemoveButton() {
        removeButton.click();
    }

    public MovieDetailPage ensurePageLoaded() {
        super.ensurePageLoaded();
        wait.until(presenceOfElementLocated(By.cssSelector("#content > section > nav > ul > li:nth-child(4) > div > div > a > img")));
        return this;
    }
}
